package com.content.scaffold.common.config.obs;

import cn.hutool.core.util.ObjectUtil;
import com.content.scaffold.common.constants.SecurityConstants;
import com.content.scaffold.common.web.RequestContext;
import com.notary.ossservice.FileOperateTemplate;
import com.notary.ossservice.service.FileService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件操作配置
 *
 * @author xiaojl
 */
@Configuration
public class FileOperateConfig {

    @Value("${notary.app-id:}")
    private String appId;

    @Bean
    public FileOperateTemplate fileOperateTemplate(FileService fileService) {
        FileOperateTemplate fileOperateTemplate = new FileOperateTemplate(fileService);
        //默认取当前用户公证处id，之后也可自行更改
        fileOperateTemplate.setNotaryOfficeIdSupplier(() ->
                ObjectUtil.isNotEmpty(RequestContext.getRequestInfo().getOfficeId()) ?
                        RequestContext.getRequestInfo().getOfficeId() : appId);
        //配置中取应用id
        fileOperateTemplate.setApplicationId(appId);
        //预设加密密钥
        fileOperateTemplate.setEncryptKey(SecurityConstants.EncryptUserKey.getOne());
        return fileOperateTemplate;
    }

}
